package com.base.servlet;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.homework.entity.Homewokmaster;
import com.homework.service.HomeWorkService;

/**
 * Servlet implementation class HomeWorkSelectServlet
 */
public class HomeWorkSelectServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HomeWorkSelectServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HomeWorkService hs=new HomeWorkService();
		String seldata=request.getParameter("seldate");
		System.out.println("seldata--"+seldata);
		String type=request.getParameter("type");
		//String 转long
//		long date1=Long.parseLong(seldata);
		
		SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd");
		Date d1;
		try {
			d1 = s.parse(seldata);
			ArrayList<Homewokmaster> hms=hs.getHomewokmasterByDateAndType(d1.getTime(), type);
			HttpSession se1=request.getSession();
			se1.setAttribute("homelist", hms);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//解决中文乱码问题
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		
		response.sendRedirect("index3.jsp");
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
